<!Doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,minimum-scale=1,user-scalable=no,maximum-scale=1,initial-scale=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="keywords" content="" />
    <meta id="m1" itemprop="name" content="2018营销大课尽在i幸会，70位实战导师等你来"/>
    <meta id="m2"  itemprop="image" content="http://api.ixinghui.com:81/ixinghui-share/img/sher.png" />
    <meta id="m3"  name="description" itemprop="description" content="睡前、晨起、奔波途中，碎片化时间，针对性学习，拒绝知识焦虑！" />
    <link rel="icon" href="../img/da.ico">
    <link href="../css/member.css" rel="stylesheet" type="text/css" />
    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js" type="text/javascript"></script>
    <title>会员说明</title>
    <script type="text/javascript" src="http://qzonestyle.gtimg.cn/qzone/qzact/common/share/share.js"></script>
</head>
<body>
    <div class="memDes">
        <img src="../img/h5/bigm@2x.png" alt="">
        <p class="p1"><img src="../img/h5/vip.png" alt=""/><span></span></p>
        <p class="p2">
            <b></b>
            <i></i>
        </p>
        <p class="p3">
            <i></i>
        </p>
        <p class="p4"><img src="../img/h5/huiqi@2x.png" alt=""/><span></span></p>
    </div>
    <div class="memDes1">
        <p class="p5"><span>会员权益</span><img src="../img/h5/vip@2x.png" alt=""></p>
        <!--<p class="p6">INSTRUCTION</p>-->
        <pre class="p7">
        </pre>
    </div>
    <div id="pay_money">
        <ul>
            <li>
                选择支付方式
            </li>
            <li>
                <i class="weixin"></i>
                <span class="span1">微信支付</span>
                <i class="select"></i>
            </li>
            <li>
                <i class="zhifubao"></i>
                <span class="span2">支付宝支付</span>
                <i class="select1"></i>
            </li>
        </ul>
    </div>
    <form id="pay_form" method="post" autocomplete="off">
        <div class="parbot2">
            <a href="javascript:void(0);" class="immediate_payment" id="immediate_payment" value="立即支付"/>开通会员</a>
        </div>
    </form>
    <div id="zhifubao"></div>
    <script type="text/javascript" src="../js/ap.js"></script>
    <script type="text/javascript" src="../js/jquery-1.12.2.min.js"></script>
    <script type="text/javascript" src="../js/session.js"></script>
    <script type="text/javascript" src="../js/cookie.js"></script>
    <script type="text/javascript" src="../js/plugin.js"></script>
    <script type="text/javascript" src="../js/index.js"></script>

    <script>
        $(function(){
            var lis=$('#pay_money>ul>li');
            var payType=11;
            for(var i=0;i<lis.length;i++){
                +function(i){
                    $(lis[i]).click(function(){
                        if(i==2){
                            $(lis[i]).prev().children('i:last').addClass('select1').removeClass('select');
                            $(lis[i]).children('i:last').addClass('select').removeClass('select1');
                            payType=10
                        }else if(i==1){
                            $(lis[i]).next().children('i:last').addClass('select1').removeClass('select');
                            $(lis[i]).children('i:last').addClass('select').removeClass('select1');
                            payType=11
                        }
    //                    console.log(payType)
                    })
                }(i)
            }

            //会员说明
            var id = $.session.get('id');
            var shareId = $.session.get('shareId');
    //        若地址栏URL为：abc.html?id=123&url=http://www.maidq.com
    //       那么，但你用上面的方法去调用：alert(GetQueryString("url"));
            function GetQueryString(name)
            {
                var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if(r!=null)return  unescape(r[2]); return null;
            }
            var code = GetQueryString('code')
            if(code==null){
                code=123;
            }
    //        console.log(code)

            var data;
            $.ajax({
                url :endpoint + "getMembersInstructionForH5 " + jsonpoint,
                data : {'userId':id},
                type:'post',
                success : function(data){
                   data=data.members;
                    console.log(data);
                    data.presentPrice-=20;
                    $('.memDes>.p1>span').html(data.phoneNo);
                    $('.memDes>.p2>b').html('￥'+data.presentPrice);
                    $('.memDes>.p2>i').html('/年');
                    $('.memDes>.p3>i').html('￥'+data.originalPrices+'/年');
                    $('.memDes>.p4>span').html('我的会期：'+data.startDate+' 至 '+data.endDate);
                    $('.memDes1>.p7').html(data.instruction);
                    //        会员价和实际价格相同时
    //                console.log(data.presentPrice,data.originalPrices)
                    if(data.presentPrice==data.originalPrices){
                        $('.p3').hide()
                    }else{
                        $('.p3').show()
                    }
                    var btn= document.querySelector('.immediate_payment')
                    btn.addEventListener('click',function(e){
                        e.preventDefault();
                        e.stopPropagation();
                        e.stopImmediatePropagation();
                        function getH5Pay(prams,callBack){
                            $.ajax({
                                async: true,
                                type: "get",
                                data: prams,
                                cache: false,
                                url: endpoint + "order/purchaseMembershipForH5" + jsonpoint,
                                success:function(data){
                                    return callBack(data);
                                }
                            })
                        }
                        console.log({
    //                                money:0.01,
                                    money:data.presentPrice,
                                    userId:id,
                                    payType:payType,
                                    plat:'web',
                                    startDate:data.startDate,
                                    endDate:data.endDate,
                                    fromUserId:shareId,
                                    code:code
                                })
                        getH5Pay(
                                {
    //                                money:0.01,
                                    money:data.presentPrice,
                                    userId:id,
                                    payType:payType,
                                    plat:'web',
                                    startDate:data.startDate,
                                    endDate:data.endDate,
                                    fromUserId:shareId,
                                    code:code
                                },
                                function(data){
    //                                console.log(data)
                                    if(payType==11){
    //                                    console.log('微信');
                                        function isWeiXin(){
                                            var ua = window.navigator.userAgent.toLowerCase();
                                            if(ua.match(/MicroMessenger/i) == 'micromessenger'){
                                                return true;
                                            }else{
                                                return false;
                                            }
                                        }
    //                                    如果非微信内核
                                        if(!isWeiXin()){
                                            window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx245428584189430f&redirect_uri=http://api.ixinghui.com/ixinghui-share/member/timetable.html&response_type=code&scope=snsapi_base&state="+shareId+"#wechat_redirect";
                                        }
                                        function onBridgeReady(){
                                            WeixinJSBridge.invoke(
                                                    'getBrandWCPayRequest',{
                                                        "appId":data.wx.appid,     //公众号名称，由商户传入
                                                        "timeStamp":data.wx.timeStamp,         //时间戳，自1970年以来的秒数
                                                        "nonceStr":data.wx.nonceStr, //随机串
                                                        "package":'prepay_id='+data.wx.prepayId,
                                                        "signType":"MD5",         //微信签名方式：
                                                        "paySign":data.wx.sign//微信签名
                                                    },
                                                    function(res){
                                                        if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                                                        window.location.href='paySuccess.html'
                                                        }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                                                    }
                                            );
                                        }
                                        if (typeof WeixinJSBridge == "undefined"){
                                            if( document.addEventListener ){
                                                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                                            }else if (document.attachEvent){
                                                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                                                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                                            }
                                        }else{
                                            onBridgeReady();
                                        }
                                    }
                                    //    支付宝部分
                                    if(payType==10){
    //                                    console.log('支付宝');
                                        $('#zhifubao').append(data.zfb);
                                        var queryParam = '';
                                        Array.prototype.slice.call(document.querySelectorAll("input[type=hidden]")).forEach(function (ele) {
                                            queryParam += '&'+ ele.name + "=" + encodeURIComponent(ele.value) ;
                                        });
                                        var gotoUrl = document.querySelector("#alipaysubmit").getAttribute('action') + queryParam;
                                        _AP.pay(gotoUrl);
                                        return false;
                                    }
                                }
                        )
                    },false)
                }
            });
        })
    </script>
</body>
</html>